{% extends "auth/base.html" %}

{% block title %}注册 - FlaskWeb{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8 col-lg-6">
        <div class="card shadow">
            <div class="card-header bg-success text-white text-center">
                <h4 class="mb-0">
                    <i class="fas fa-user-plus me-2"></i>用户注册
                </h4>
            </div>
            <div class="card-body">
                <form method="POST" action="{{ url_for('auth.register') }}">
                    {{ form.hidden_tag() }}
                    
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            {{ form.username.label(class="form-label") }}
                            {{ form.username(class="form-control" + (" is-invalid" if form.username.errors else ""), placeholder="用户名") }}
                            {% if form.username.errors %}
                                <div class="invalid-feedback">
                                    {% for error in form.username.errors %}
                                        {{ error }}
                                    {% endfor %}
                                </div>
                            {% endif %}
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            {{ form.email.label(class="form-label") }}
                            {{ form.email(class="form-control" + (" is-invalid" if form.email.errors else ""), placeholder="邮箱") }}
                            {% if form.email.errors %}
                                <div class="invalid-feedback">
                                    {% for error in form.email.errors %}
                                        {{ error }}
                                    {% endfor %}
                                </div>
                            {% endif %}
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            {{ form.password.label(class="form-label") }}
                            <div class="input-group">
                                {{ form.password(class="form-control" + (" is-invalid" if form.password.errors else ""), placeholder="密码", id="password") }}
                                <button class="btn btn-outline-secondary" type="button" id="toggle-password">
                                    <i class="fas fa-eye"></i>
                                </button>
                            </div>
                            {% if form.password.errors %}
                                <div class="invalid-feedback">
                                    {% for error in form.password.errors %}
                                        {{ error }}
                                    {% endfor %}
                                </div>
                            {% endif %}
                            <div class="form-text">密码至少8位，包含字母和数字</div>
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            {{ form.confirm_password.label(class="form-label") }}
                            <div class="input-group">
                                {{ form.confirm_password(class="form-control" + (" is-invalid" if form.confirm_password.errors else ""), placeholder="确认密码", id="confirm_password") }}
                                <button class="btn btn-outline-secondary" type="button" id="toggle-confirm-password">
                                    <i class="fas fa-eye"></i>
                                </button>
                            </div>
                            {% if form.confirm_password.errors %}
                                <div class="invalid-feedback">
                                    {% for error in form.confirm_password.errors %}
                                        {{ error }}
                                    {% endfor %}
                                </div>
                            {% endif %}
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            {{ form.nickname.label(class="form-label") }}
                            {{ form.nickname(class="form-control" + (" is-invalid" if form.nickname.errors else ""), placeholder="昵称") }}
                            {% if form.nickname.errors %}
                                <div class="invalid-feedback">
                                    {% for error in form.nickname.errors %}
                                        {{ error }}
                                    {% endfor %}
                                </div>
                            {% endif %}
                        </div>
                        
                        <div class="col-md-6 mb-3">
                            {{ form.age.label(class="form-label") }}
                            {{ form.age(class="form-control" + (" is-invalid" if form.age.errors else ""), placeholder="年龄") }}
                            {% if form.age.errors %}
                                <div class="invalid-feedback">
                                    {% for error in form.age.errors %}
                                        {{ error }}
                                    {% endfor %}
                                </div>
                            {% endif %}
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        {{ form.bio.label(class="form-label") }}
                        {{ form.bio(class="form-control" + (" is-invalid" if form.bio.errors else ""), placeholder="个人简介", rows="3") }}
                        {% if form.bio.errors %}
                            <div class="invalid-feedback">
                                {% for error in form.bio.errors %}
                                    {{ error }}
                                {% endfor %}
                            {% endif %}
                        </div>
                    
                    <div class="mb-3">
                        {{ form.gender.label(class="form-label") }}
                        {{ form.gender(class="form-select" + (" is-invalid" if form.gender.errors else "")) }}
                        {% if form.gender.errors %}
                            <div class="invalid-feedback">
                                {% for error in form.gender.errors %}
                                    {{ error }}
                                {% endfor %}
                            </div>
                        {% endif %}
                    </div>
                    
                    <div class="mb-3">
                        {{ form.phone.label(class="form-label") }}
                        {{ form.phone(class="form-control" + (" is-invalid" if form.phone.errors else ""), placeholder="手机号码") }}
                        {% if form.phone.errors %}
                            <div class="invalid-feedback">
                                {% for error in form.phone.errors %}
                                    {{ error }}
                                {% endfor %}
                            </div>
                        {% endif %}
                    </div>
                    
                    <div class="mb-3 form-check">
                        {{ form.is_public(class="form-check-input") }}
                        {{ form.is_public.label(class="form-check-label") }}
                    </div>
                    
                    <div class="d-grid gap-2">
                        {{ form.submit(class="btn btn-success") }}
                    </div>
                </form>
                
                <div class="text-center my-3">
                    <span class="text-muted">或</span>
                </div>
                
                <!-- OAuth注册选项 -->
                <div class="d-grid gap-2">
                    <a href="{{ url_for('oauth.github_login') }}" class="btn btn-dark">
                        <i class="fab fa-github me-2"></i>使用GitHub注册
                    </a>
                </div>
            </div>
            <div class="card-footer text-center">
                <small class="text-muted">
                    已有账号？<a href="{{ url_for('auth.login') }}">立即登录</a>
                </small>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
    // 密码显示/隐藏切换
    document.getElementById('toggle-password').addEventListener('click', function() {
        const passwordInput = document.getElementById('password');
        const icon = this.querySelector('i');
        
        if (passwordInput.type === 'password') {
            passwordInput.type = 'text';
            icon.classList.remove('fa-eye');
            icon.classList.add('fa-eye-slash');
        } else {
            passwordInput.type = 'password';
            icon.classList.remove('fa-eye-slash');
            icon.classList.add('fa-eye');
        }
    });
    
    document.getElementById('toggle-confirm-password').addEventListener('click', function() {
        const passwordInput = document.getElementById('confirm_password');
        const icon = this.querySelector('i');
        
        if (passwordInput.type === 'password') {
            passwordInput.type = 'text';
            icon.classList.remove('fa-eye');
            icon.classList.add('fa-eye-slash');
        } else {
            passwordInput.type = 'password';
            icon.classList.remove('fa-eye-slash');
            icon.classList.add('fa-eye');
        }
    });
</script>
{% endblock %}